// packageE/regionalAwards/regionalAwardsRecord/regionalAwardsRecord.js
var app = getApp();
Page({

  /**
	 * 页面的初始数据
	 */
  data: {
    id:0,

    isLoadMore: true,
    total_page: 0,
    page: 1,
    listData:[]
  },

  /**
	 * 生命周期函数--监听页面加载
	 */
  onLoad: function (options) {
    this.data.id = options.id;
    this.getData();
  },

  /**
	 * 生命周期函数--监听页面初次渲染完成
	 */
  onReady: function () {

  },

  /**
	 * 生命周期函数--监听页面显示
	 */
  onShow: function () {

  },

  /**
	 * 生命周期函数--监听页面隐藏
	 */
  onHide: function () {

  },

  /**
	 * 生命周期函数--监听页面卸载
	 */
  onUnload: function () {

  },

  /**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
  onPullDownRefresh: function () {

  },

  /**
	 * 页面上拉触底事件的处理函数
	 */
  onReachBottom: function () {
    if (this.data.isLoadMore) {
      this._getMoreData();
    } else {
      console.log('没有更多数据');
    }
  },

  /**
	 * 用户点击右上角分享
	 */
  onShareAppMessage: function () {

  },

  _getMoreData(){
    let that = this;
    if (this.data.page >= this.data.total_page) {
      return;
    } else {
      let urlStr = app.getNetAddresss('plugin.regional-reward.Frontend.controllers.reward.index');
      this.data.page++;
      app._postNetWork({
        url: urlStr,
        data: {
          page:this.data.page,
          quota_id:this.data.id
        },
        success: (resdata)=> {
          let res = resdata.data;
          if(res.result!=1) return;
          if (res.data.current_page >= res.data.last_page) {
            that.setData({
              isLoadMore: false
            });
          }
          let listData = this.data.listData;
          listData.push(...res.data.getRecord.data);
          this.setData({listData});
        },
        fail: function(res) {
          console.log(res.msg);
        }
      });
    }
  },
  getData(){
    let that=this;
    let urlStr = app.getNetAddresss('plugin.regional-reward.Frontend.controllers.reward.index');
    app._postNetWork({
      url: urlStr,
      data:{quota_id:this.data.id},
      success: (resdata)=> {
        let res = resdata.data;
        if(res.result!=1) return this.tips(res.msg);


        this.data.total_page = res.data.last_page||0;
        if (res.data.current_page >= res.data.last_page) {
          that.setData({
            isLoadMore: false
          });
        }
        this.setData({
          statistics:res.data.statistics,
          info:res.data.info,
          listData:res.data.data
        });
      },
      fail: function(res) {
        console.log(res.msg);
      }
    });
  },

  tips(msg){
    wx.showToast({
      title: msg,
      icon: 'none',
      duration: 2000
    });
    return false;
  }



});